#include <REGX52.H>
#include "LCD1602.h"
#include "delay.h"

unsigned char MatrixKey(){
	unsigned char KeyNumber=0,i,j;
	for(i=3;i>=0;i--){
		P1=0xff;
		P1^=1<<i;
		for(j=7;j>3;j--)
			if(!(P1&(1<<j))){
				delay(20);
				while(!(P1&(1<<j)));
				delay(20);
				KeyNumber=((7-j)<<2)|(4-i);
			}
	}
	return KeyNumber;
}